function fmtGender(value) {
    return value==1?"男":"女";
}
function fmtRole(value) {
    /*console.log(value)*/
    return value.roleName;
}
function queryUser() {
    var formParams = $("#queryForm").serialize();
    var query = Qs.parse(formParams);
    $("#userTb").bootstrapTable("refresh", {query})
}
function queryParams(params) {
    var formParams = $("#queryForm").serialize();
    var query = Qs.parse(formParams);
    Object.assign(params, query);
    console.log(params);
    return params;
}

/*循环角色role*/
    $.get("sys/role/list")
    .done(list=>{
        list.forEach(function (role) {
            var opt = $("<option/>");
            opt.val(role.id);
            opt.text(role.roleName);
            opt.appendTo("#queryForm [name=roleId]");
        });
    })

//修改
var actionEvents = {
        "click .click":function(event, value, row) {
        console.log(row);
}
}
function actionFormatter() {
    var edit = `<button class="btn btn-warning edit"><i class="glyphicon glyphicon-edit btn-small edit"></i> 修改用户</button>`
    return edit;
}
function detailFormatter(index, row) {
        let html = `<table class="table table-bordered">
                        <tr>
                            <td>联系人姓名</td>
                            <td>联系人电话</td>
                            <td>联系地址</td>
                        <tr>`;
    $(row.addressList).each(function () {
        html+= `<tr>
                    <td>${this.contact}</td>    
                    <td>${this.tel}</td>
                    <td>${this.addressDesc}</td>
                </tr>`
    })
    html+=`</table>`
    return html;
}
//用户授权模态框
$("#grant").dialog({
    title:"用户授权",
    btnBind() {
        var arr1 = $("#userTb").bootstrapTable("getSelections");
        var arr2 = $("#grant table").bootstrapTable("getSelections");
        var params =`userId=${arr1[0].id}&roleId=${arr2[0].id}`;
        $.post('sys/user/grant',params)
            .done(msg=>{
                $("#userTb").bootstrapTable("refresh");
                $("#grant").dialog("hide");
                toastr.success(msg);
            })
    }
})
function grant() {
    var arr = $("#userTb").bootstrapTable("getSelections");
    if (arr.length != 1) {
        swal("信息提示","请至少选择一项待授权")
    }
    $("#grant table").bootstrapTable("checkBy",{field:"id",values:[arr[0].userRole]})
    $("#grant").dialog("show");
}